home *** CD-ROM | disk | FTP | other *** search
/ develop, the CD; issue 1 / Apple_Develop_1989.bin / Realistic Color / RW Bulls Eye / RW Bullseye.c < prev    next >
C/C++ Source or Header  |  1989-11-16  |  3KB  |  158 lines

  1. /*
  2.  * file: RW Bullseye.c
  3.  *
  4.  * started 7 August 1988 23:06
  5.  * david van brink
  6.  *
  7.  * A Sample of NewGWorld in action.
  8.  *
  9.  ************************************
  10.  * Inclusions
  11.  ************************************/
  12.  
  13. #include "colortoolbox.h"
  14. #include "EventMgr.h"
  15. #include "MenuMgr.h"
  16. #include "BigEasy2.h"
  17. #include "QuickDraw32Bit.h"
  18.  
  19. /************************************
  20. * Types and globals
  21. ************************************/
  22. extern Rect gBigRect;
  23. GWorldPtr gMyOffG;
  24. Rect dOffBounds = {0,0,256,256};
  25.  
  26. DrawSplug()
  27. /*
  28.  * Draws the window.
  29.  */
  30.     {
  31.     Rect r;
  32.  
  33.     EraseRect(&gBigRect);
  34.  
  35.     ForeColor(blackColor);
  36.     CopyBits(&gMyOffG->portPixMap,&thePort->portBits,&dOffBounds,&dOffBounds,ditherCopy,0);/**/
  37.     }
  38.  
  39.  
  40. int ClickSplug(n,p)
  41. /*
  42.  * Come here for a click in the window.
  43.  */
  44.      short n;            /* window number        */
  45.     Point p;            /* where clicked        */
  46.     {
  47.     }
  48.  
  49. GoAwaySplug(n)
  50. /*
  51.  * Close that window...
  52.  */
  53.      short n;
  54.     {
  55.     UninstallWindow(n);
  56.     }
  57.  
  58. int ActivateSplug(n)
  59.     {
  60.     SetMenuItem(23,true,0,0,nil);                /* enable "Close" menu item        */
  61.     SetMenuItem(24,false,0,0,nil);                /* disable "Open" menu item        */
  62.     KillEds();
  63.     }
  64.  
  65. int DeactivateSplug(n)
  66.     {
  67.     SetMenuItem(23,false,0,0,nil);                /* disable "Close" menu item        */
  68.     SetMenuItem(24,true,0,0,nil);                /* enable "Open" menu item        */
  69.     }
  70.  
  71. int pnull(){}
  72. letsquit(){gQuitApp++;}
  73.  
  74. KillEds()
  75.     {
  76.     EnDisEdits(0,0,0,0,0);
  77.     }
  78.  
  79. OpenWindow()
  80.     {
  81.     Rect r;
  82.  
  83.     SetRect(&r,100,100,100+dOffBounds.right,100+dOffBounds.bottom);
  84.  
  85.     InstallWindow(1,"\pWindow",&r,0,1,
  86.             (FP)DrawSplug,ClickSplug,pnull,GoAwaySplug,
  87.             DeactivateSplug,ActivateSplug,pnull);
  88.     }
  89.  
  90. InitVars()
  91. /*
  92.  * Called once at startup: yes, it
  93.  * inits the vars.
  94.  */
  95.     {
  96.     GDHandle oldGD;
  97.     GWorldPtr oldGW;
  98.     HSVColor hsvc;
  99.     RGBColor rgbc;
  100.     long x;
  101.     Rect r;
  102.     short QDErr;
  103.  
  104.     GetGWorld(&oldGW,&oldGD);
  105.  
  106.     QDErr = NewGWorld(&gMyOffG,32,&dOffBounds,nil,nil,0);
  107.     if (QDErr)  /* exit_to_shell */ ;
  108.     LockPixels(gMyOffG->portPixMap);
  109.  
  110.     SetGWorld(gMyOffG,nil);
  111.  
  112.     for(x = 0; x<dOffBounds.right; x++)
  113.         {
  114.         rgbc.red = rgbc.green = rgbc.blue = x * 65535 / (dOffBounds.right - 1);
  115.         RGBForeColor(&rgbc);
  116.         MoveTo(x,0);
  117.         LineTo(x,dOffBounds.bottom);
  118.         }
  119.  
  120.     r = dOffBounds;
  121.     hsvc.value = 65535;
  122.     hsvc.saturation = 65535;
  123.     for (x = dOffBounds.right/2; x; x--)
  124.         {
  125.         hsvc.hue = x * 131070/(dOffBounds.right - 1);
  126.         HSV2RGB(&hsvc,&rgbc);
  127.         RGBForeColor(&rgbc);
  128.         FrameOval(&r);
  129.         InsetRect(&r,1,1);
  130.         }
  131.  
  132.     SetGWorld(oldGW,oldGD);
  133.     }
  134.  
  135.  
  136. Bootstrap()
  137.     {
  138.     InitVars();
  139.  
  140. /*** Menu 2 ***/
  141.     InstallMenu("\pFile",pnull,0);
  142.     InstallItem("\pOpen/O",OpenWindow,23);
  143.     InstallItem("\pClose/W",GoAwaySplug,-24);
  144.     InstallItem("\p(-",pnull,0);
  145.     InstallItem("\pQuit/Q",letsquit,0);
  146.  
  147. /*** Menu 3 ***/
  148.     InstallEditMenu(pnull,pnull,pnull,pnull,pnull);
  149.  
  150.     KillEds();
  151.  
  152.     OpenWindow();
  153.  
  154.     }
  155.  
  156.  
  157.  
  158.